home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / t100.zoo / t100.c < prev    next >
C/C++ Source or Header  |  1991-09-22  |  20KB  |  957 lines

  1. /*
  2.  *    t100 - simple term emulator. vt52 and ANSI (much of vt100)
  3.  *
  4.  *    by Bill Rosenkranz (rosenkra@convex.com).
  5.  *
  6.  *    based on st52 program by Nick Castellano (entropy@ai.mit.edu) but
  7.  *    greatly changed so it bears little resemblence. i added the vt100
  8.  *    support, including font changes. also lifted rs232init from Howard
  9.  *    Chu's tip and rs232cd (carrier detect) from Steve Yelvington.
  10.  *
  11.  *    this was written with gcc 1.40 (and MiNT 10 libraries).
  12.  *
  13.  *    currently it is hardwired to vt100 (vt100_mode==1 always). i am
  14.  *    not sure why you'd want vt52 anyway. you can toggle this by adding
  15.  *    code to set vt100_mode to 0 (the host better know you changed!).
  16.  *    my reference for the ANSI/vt100 escape codes was an old Falco
  17.  *    terminal manual. it may not be accurate/modern/complete but does
  18.  *    seem accurate for all the escapes i find in standard vt100 termcap.
  19.  *
  20.  *    it should be easy to hack in an escape to execute shell commands.
  21.  *    i just have not done it. that way you could start up a kermit
  22.  *    or xmodem or whatever. i have not tested this under MiNT or mgr.
  23.  *
  24.  *    restrictions: to (re)set the fonts, i do a line A init ($A000)
  25.  *    to get the fonthdr pointer and from there get the address of the
  26.  *    font data. i poke in a new address to my own data, being careful
  27.  *    to set it back on exit (i hope :-). this means if your big-screen
  28.  *    monitor can't support this, you are SOL. it also won't run on a
  29.  *    TT since line A went bye-bye. note that you can always recompile
  30.  *    with -UUSE_FONTS and it should work fine on any system. you just
  31.  *    won't have bold and underline.
  32.  *
  33.  *    also, if you define SET_RS232_INIT at compile time, this relies
  34.  *    on Rsconf returning a value. my understanding is that this does
  35.  *    not work on TOS 1.0. the safe bet would be to check the TOS
  36.  *    version. i have not tested this part of the code. currently,
  37.  *    the rs232 paramaters are hardwired. i would set it from the
  38.  *    control panel.
  39.  *
  40.  *    major problem: i can't figure out how to tell the host we are an
  41.  *    80x25 term without changing /etc/termcap (difficult to do without
  42.  *    the root passwd). setting TERMCAP did not help, at least with
  43.  *    GNU emacs and less. maybe there is a termcap for 80x25 but i never
  44.  *    checked. standard vt100 and vt100n has li set to 24. emacs manual
  45.  *    sez stuff about this (maybe set TERM to vt100-25?). i have no idea
  46.  *    about VMS and other non-unix systems with user library routines whose
  47.  *    names contain "$". why bother? :-)
  48.  */
  49.  
  50. #ifndef lint
  51. static char *rcsid_t100_c = "$Id: t100.c,v 1.0 1991/09/12 20:32:56 rosenkra Exp $";
  52. #endif
  53.  
  54. /*
  55.  * $Log: t100.c,v $
  56.  * Revision 1.0  1991/09/12  20:32:56  rosenkra
  57.  * Initial revision
  58.  *
  59.  */
  60.  
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. #include <unistd.h>
  64. #include <string.h>
  65. #include <osbind.h>
  66. #include <mintbind.h>
  67. #include <signal.h>
  68. #include "t100.h"
  69.  
  70.  
  71.  
  72. #define MINTID        "MiNT"        /* MiNT's cookie string */
  73. #define MAXWAIT        1000        /* see note in main loop */
  74. #define PROMPT_STRING    "\n\rt100> "    /* MUST contain a newline */
  75.  
  76. #define NEWLINE        10        /* common chars */
  77. #define ESC        27
  78. #define RETURN        13
  79.  
  80.  
  81. /*
  82.  *    globals
  83.  */
  84. char        iobuf[8192];        /* new iorec for rs232 (first half */
  85.                     /* is in, second half out) */
  86. _IOREC           *recsav;            /* ptr to iorec struct */
  87. _IOREC        oldirec;        /* old input iorec */
  88. _IOREC        oldorec;        /* old output iorec */
  89.  
  90. int        par  = 0;        /* none, odd, even - 0, 1, 2 */
  91. int        baud = 4;        /* see baud table 4=2400 */
  92. int        echo = 0;        /* 0=off, 1=on */
  93. int        flow = 0;        /* none, xon/xoff, rts/cts */
  94.  
  95. int        ucr, rsr, tsr, scr;    /* for resetting rs232 regs */
  96.  
  97. char           *bauds[] = {"19200","9600","4800","3600","2400","2000",
  98.                "1800","1200","600","300","200","150","134",
  99.                "110","75","50"};        /* unused */
  100.  
  101. int        vt100_mode = 1;        /* 0 means revert to vt52 */
  102. long        mintcookie = 0L;    /* if MiNT this will be non-NULL */
  103.  
  104. /*
  105.  *    vt100 modes, etc...
  106.  */
  107. int        bold      = 0;        /* OFF 1m */
  108. int        underline = 0;        /* OFF 4m */
  109. int        blinking  = 0;        /* OFF 5m */
  110. int        reverse   = 0;        /* OFF 7m */
  111. int        wrap      = 1;        /* ON (set) */
  112. int        video     = 0;        /* 0=normal (reset) */
  113. int        repeat    = 1;        /* ON (set) */
  114. int        curskey   = 0;        /* OFF (reset) */
  115. int        keypad    = 0;        /* 0=normal (reset) */
  116. int        colwidth  = 0;        /* 0=80 (reset), 1=132 */
  117. int        smooth    = 0;        /* OFF (reset) */
  118. int        origmode  = 0;        /* 0=normal (reset) */
  119.  
  120. short        kbinit, kbrpt;        /* saved key repeat stuff */
  121.  
  122. int        outtran[256];        /* char xlation table */
  123.  
  124.  
  125.  
  126. /*------------------------------*/
  127. /*    main            */
  128. /*------------------------------*/
  129. int main (int argc, char *argv[], char *envp[])
  130. {
  131.     short        kbret;
  132.     int        x;
  133.     register long    key;            /* raw Bconin value */
  134.     register int    gnsrgh = MAXWAIT;
  135.     register int    c;
  136. #ifdef JUNK
  137.     /* this was in st52 code. i don't use it...(it was #ifdef'd already) */
  138.     char           *terminal;
  139.     char           *etmp;
  140.     char           *newenv;
  141.  
  142.  
  143.     etmp = (char *) envp;
  144.  
  145.     terminal = getenv ("TERM");
  146. #ifdef DEBUG
  147.     Cconws ("Terminal type:  ");
  148.     puts (terminal);
  149. #endif
  150.  
  151.     if (strcmp (terminal, "mgr") == 0)
  152.     {
  153.  
  154. #ifdef DEBUG
  155.         puts ("yep");
  156.         printf ("value: %d\n",
  157.         Pexec (200, "e:\\mint\\mgr\\bin\\vt52.prg",
  158.             "e:\\mint\\mgr\\bin\\vt52.prg t100", envp));
  159. #else
  160.         Pexec (200, "e:\\mint\\mgr\\bin\\vt52.prg",
  161.             "e:\\mint\\mgr\\bin\\vt52.prg t100", envp);
  162. #endif
  163.     }
  164.  
  165. #endif /*JUNK*/
  166.  
  167.  
  168.  
  169.     /*
  170.      *   some initializations: key repeat (save old) and wrap ON
  171.      */
  172.     kbret  = (short) Kbrate (15, 2);/* repeat ESC [ ? 8 h */
  173.     kbinit = (kbret >> 8) & 0x00ff;
  174.     kbrpt  = kbret & 0x00ff;
  175.  
  176.     Bconout (CON, (int) 27);    /* wrap ESC [ ? 7 h */
  177.     Bconout (CON, (int) 'v');
  178.  
  179.  
  180.  
  181.     /*
  182.      *   set up output char translation array (normally output==input,
  183.      *   but you can remap if you want here)
  184.      */
  185.     for (x = 0; x < 256; x++)
  186.         outtran[x] = x;
  187. #ifdef SWAP_DEL_AND_BS
  188.     /*
  189.      *   this swaps DEL and BS
  190.      */
  191.     outtran[127] = 8;
  192.     outtran[8]   = 127;
  193. #endif
  194.  
  195.  
  196.     /*
  197.      *   check for MiNT cookie
  198.      */
  199.     mintcookie = getcookie (MINTID);
  200. #ifdef DEBUG
  201.     printf ("MiNT cookie %lx detected\n", mintcookie);
  202. #endif
  203.  
  204.  
  205.  
  206. #ifdef USE_FONTS
  207.     /*
  208.      *   set fonts
  209.      */
  210. #ifdef DEBUG
  211.     Cconws ("\n\rset fonts...\n\r\n\r");
  212. #endif
  213.     if (vt100_mode)
  214.         fnt_roman ();
  215.  
  216. #if 0
  217. /* test fonts */
  218.             Cconws ("Roman font (normal)\n\r");
  219.     fnt_bold ();    Cconws ("BOLD font\n\r");
  220.     fnt_uline ();    Cconws ("uline font\n\r");
  221.     fnt_reverse ();    Cconws ("reverse font\n\r");
  222.     fnt_roman ();    Cconws ("back to Roman\n\r\n\r\n\r");
  223.  
  224.             Cconws ("roman ");
  225.     fnt_bold ();    Cconws ("bold ");
  226.     fnt_uline ();    Cconws ("uline ");
  227.     fnt_reverse ();    Cconws ("reverse ");
  228.     fnt_roman ();    Cconws ("roman\n\r\n\r");
  229. #endif
  230. #else /*! USE_FONTS*/
  231.     vt100_mode = 0;
  232. #endif /*USE_FONTS*/
  233.  
  234. #if 0
  235. /* test Setcolor */
  236.     Setcolor (0,0);
  237.     Setcolor (1,0x777);
  238.     Cconws ("any key\n\r");
  239.     Crawcin ();
  240.     Setcolor (0,0x777);
  241.     Setcolor (1,0);
  242. #endif
  243.  
  244.  
  245.     /*
  246.      *   introductions...
  247.      */
  248.     blurb ();
  249.  
  250.  
  251.     /*
  252.      *   initialize rs232 (buffers and baud)
  253.      */
  254.     Cconws ("\n\rinitialize rs232...\n\r");
  255.     rs232init ();
  256.     Cconws ("baud set to 2400.\n\r");
  257.  
  258.  
  259.     /*
  260.      *   prompt
  261.      */
  262.     Cconws (PROMPT_STRING);
  263.  
  264.  
  265.     /*
  266.      *   main loop...
  267.      */
  268.     for (;;)
  269.     {
  270.         /*
  271.          *   if there are characters at the AUX port, and we are
  272.          *   not going to interrupt, print them. without the
  273.          *   gnsrgh value, we can't interrupt and send a char.
  274.          *   MAXWAIT controls how many chars we let in before
  275.          *   checking the keyboard. 1000 seems reasonable.
  276.          */
  277.         if (Bconstat (AUX) && gnsrgh--)
  278.         {
  279.             /*
  280.              *   get char
  281.              */
  282.             c = (int) Bconin (AUX);
  283.  
  284.             /*
  285.              *   check for newline. if we are connected do nothing
  286.              *   special. otherwise print PROMPT_STRING (which
  287.              *   must have the newline we ignore in it)
  288.              */
  289.             if (c == NEWLINE)
  290.             {
  291.                 /*
  292.                  *   if carrier detected...
  293.                  */
  294.                 if (rs232cd ())
  295.                 {
  296.                     /*
  297.                      *   ...output the newline...
  298.                      */
  299.                     Bconout (CON, (int) c);
  300.                 }
  301.                 else
  302.                 {
  303.                     /*
  304.                      *   ...otherwise do our prompt
  305.                      */
  306.                     Cconws (PROMPT_STRING);
  307.                 }
  308.             }
  309. #ifdef EMUL_VT100
  310.             else if ((c == ESC) && vt100_mode